﻿@model  WaiGaoQiaoWeb.Models.OutstockGroupDetailedVM
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("form", "validationEngine", "dp")
    @Html.Js("form", "validate", "unobtrusive", "inlinevalidation", "datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").makeValidationInline();
            $("#Amount").attr("readonly", true);
            $("#OutstockDt1").datepicker({ dateFormat: 'yy-mm-dd' });
            $.post('@Url.Action("RtnGoodsName", "Test")', { "Id": $("#Goods_ID").val() }, function (data) {
                $("#Con_GoodsInfoGoodsName").val(data);
                $("#Con_GoodsInfoId").val($("#Goods_ID").val());
            });
            var option = {
                height: 258,
                width: 790,
                url: '@Url.Action("GetDetailListByOrderNo")',
                dataType: 'json',
                colModel: [
                    { display: '编号', name: 'ID', width: 10, sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '出库日期', name: 'OutstockDt', width: 80, sortable: false, hide: false, align: 'left' },
					{ display: '仓库', name: 'Warehouse_ID', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '班组', name: 'Group_Id', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '食材', name: 'Goods_Id', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'Price', width: 60, sortable: false, align: 'left' },
				    { display: '金额', name: 'Amount', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '领用人', name: 'LeadMan', width: 60, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 80, sortable: false, hide: true, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 60, sortable: false, hide: true, align: 'left' },
                    { display: '订单号', name: 'OrderNo', width: 80, sortable: false, hide: true, align: 'left' }
             	],
                title: false,
                singleselected: true,
                usepager: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 15, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                //rowhandler: singleclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                //onToggleCol: dblClick, //当在行之间转换时
                rowbinddata: true,
                query: $("#OrderNo").val()
            };
            var grid = $("#Outstock_T").flexigrid(option);
            //自动计算金额
            $("#Price").bind("blur", function () {
                var c = $("#Count").val();
                var p = $("#Price").val();
                $("#Amount").val(c * p);
            });
            //保存
            $("#btnSave").click(function (event) {
                var vid = $("#Con_GoodsInfoId").val();
                var vcount = $("#Count").val();
                var vprice = $("#Price").val();
                var vaddedit = $("#AddEdit").val();
                var voldcount = $("#OldCount").val();
                var vsel = vid + ',' + vcount + ',' + vprice + ',' + vaddedit + "," + voldcount;
                if (!$("#frmGroupDetail").valid()) {
                    return false;
                }
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("OutStockYzh1", "OutStockGroup")',
                    data: { sel: vsel },
                    dataType: "json",
                    success: function (msg) {
                        if (msg == false) {
                            showLoadingMsg("库存不足", { left: 300, top: 2 }, true, 3000);
                            return false;
                        }
                        else {
                            $("#Goods_ID").val($("#Con_GoodsInfoId").val());
                            if (!$("#frmGroupDetail").valid()) {
                                return false;
                            }
                            $('#frmGroupDetail').ajaxSubmit(function (callback) {
                                if (callback) {
                                    refresh();
                                }
                            });
                        }
                    }
                });
            });

            $("#Price").bind("change", function () {
                var price = $("#Price").val();
                var count = $("#Count").val();
                $("#Amount").val(price * count);
            });
            $("#Con_GoodsInfoGoodsName").bind("blur", function (sel) {
                var strclassid = $("#Con_GoodsInfoId").val();
                if (strclassid > 0) {
                    $("#Price").empty();
                    $.ajax({
                        type: "POST",
                        contentType: "application/json;utf-8",
                        data: "{goodsId:'" + strclassid + "'}",
                        url: '@Url.Action("GetPriceListByGoodsId", "Test")',
                        success: function (msg) {
                            for (var i = 0; i < msg.length; i++) {

                                $("#Price").append(("<option value='" + msg[i].Text + "'>" + msg[i].Value + "</option>"));
                            }
                        }
                    });
                } //if
            });
            //关闭
            $("#btnCancel").click(function (e) {
                if ($("#ID").val() != "0") {
                    CloseModelWindow(null, true);
                    return false;
                }
                if (parent) {
                    for (var i = 0; i < parent.document.frames.length; i++) {
                        if (parent.document.frames[i].document.getElementById("orderno")) {
                            parent.document.frames[i].document.getElementById("orderno").value = $("#OrderNo").val();
                        }
                    }
                    CloseModelWindow(null, true);
                }
            });
            $("#btnDel").click(function () {
                if ($('.trSelected', grid).length == 0) {
                    showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                    return false;
                } else {
                    if (confirm("确定要删除吗?")) {
                        var rowcount = 0;
                        var items = $('.trSelected', grid);
                        for (var i = 0; i < items.length; i++) {
                            var id = items[i].id.substr(3);
                            $.ajax({
                                url: '@Url.Action("Delete")',
                                type: "POST",
                                data: { id: id },
                                async: false,
                                success: function (data) {
                                    if (data) {
                                        $("#Outstock_T").flexOptions(option).flexReload();
                                    }
                                },
                                error: function () {
                                }
                            });
                        } //for
                    }
                }
            });
            function refresh() {
                showLoadingMsg("操作成功", { left: 300, top: 2 }, true, 3000);
                $("#Outstock_T").flexOptions(option).flexReload();

            }
        })
    
    </script>
}
<div style="padding: 5px;">
    @using (Html.BeginForm("SaveGroupDetail", "OutstockGroup", FormMethod.Post, new { id = "frmGroupDetail" }))
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.OperatorID)
        @Html.HiddenFor(model => model.OrderNo)
        @Html.HiddenFor(model => model.RecordDateTime1)
        @Html.HiddenFor(model => model.OldCount)
        @Html.HiddenFor(model => model.AddEdit)
        <table style="width: 100%;">
            <tr>
                <td colspan="4">
                    <br />
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.OutstockDt1)
                </td>
                <td>@Html.TextBoxFor(model => model.OutstockDt1, new { @style = "width:145px;", @ReadOnly = true })
                    @Html.ValidationMessageFor(model => model.OutstockDt1)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Goods_ID)
                </td>
                <td>
                    @Html.Partial("RtnSpoGoodsStocksList", new Model.WaiGaoQiao.Con_GoodsInfo())
                    @Html.HiddenFor(model => model.Goods_ID)
                    @Html.ValidationMessageFor(model => model.Goods_ID)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Warehouse_ID)
                </td>
                <td>@Html.DropDownListFor(model => model.Warehouse_ID,
                                        ViewData["GetWarehouse"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:152px; height:22px; font-size:13px;" })
                    <span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Count)
                </td>
                <td>@Html.TextBoxFor(model => model.Count)
                    @Html.ValidationMessageFor(model => model.Count)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Group_ID)
                </td>
                <td>@Html.DropDownListFor(model => model.Group_ID,
                                        ViewData["GetGroup"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:152px; height:22px; font-size:13px;" })
                    <span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Price)
                </td>
                <td>@Html.DropDownListFor(model => model.Price,
                                        ViewData["Price"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:152px; height:22px; font-size:13px;" })
                    @Html.ValidationMessageFor(model => model.Price)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.LeadMan)
                </td>
                <td>@Html.TextBoxFor(model => model.LeadMan)
                    @Html.ValidationMessageFor(model => model.LeadMan)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Amount)
                </td>
                <td>@Html.TextBoxFor(model => model.Amount, new { @ReadOnly = "true" })
                    @Html.ValidationMessageFor(model => model.Amount)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr style="text-align: center;">
                <td>
                </td>
                <td>
                </td>
                <td colspan="2" align="right">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> <a
                        id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a> <a id="btnCancel"
                            class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="overflow: scroll;">
            <table id="Outstock_T" style="display: none;">
            </table>
        </div>
 
    }</div>
